import { drizzle } from 'drizzle-orm/mysql2';
import { migrate } from 'drizzle-orm/mysql2/migrator';
import * as mysql from 'mysql2/promise';
import * as dotenv from 'dotenv';

dotenv.config();

async function main() {
  console.log('开始数据库迁移...');

  try {
    const connection = await mysql.createConnection({
      host: process.env.DB_HOST,
      port: Number(process.env.DB_PORT),
      user: process.env.DB_USER,
      password: process.env.DB_PASSWORD,
      database: process.env.DB_NAME,
    });

    const db = drizzle(connection);

    // 执行迁移
    await migrate(db, { migrationsFolder: './drizzle' });

    console.log('数据库迁移成功完成！');
    await connection.end();
  } catch (error) {
    console.error('数据库迁移失败:', error);
    process.exit(1);
  }
}

main(); 